home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 September / CAG09.ISO / Programos / systemtweaker.exe / {app} / library.dat / win32evtlogutil.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-12  |  3.7 KB  |  106 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import win32api
  5. import win32con
  6. import winerror
  7. import win32evtlog
  8. error = win32api.error
  9. langid = win32api.MAKELANGID(win32con.LANG_NEUTRAL, win32con.SUBLANG_NEUTRAL)
  10.  
  11. def AddSourceToRegistry(appName, msgDLL = None, eventLogType = 'Application', eventLogFlags = None):
  12.     if msgDLL is None:
  13.         msgDLL = win32evtlog.__file__
  14.     
  15.     hkey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (eventLogType, appName))
  16.     win32api.RegSetValueEx(hkey, 'EventMessageFile', 0, win32con.REG_EXPAND_SZ, msgDLL)
  17.     if eventLogFlags is None:
  18.         eventLogFlags = win32evtlog.EVENTLOG_ERROR_TYPE | win32evtlog.EVENTLOG_WARNING_TYPE | win32evtlog.EVENTLOG_INFORMATION_TYPE
  19.     
  20.     win32api.RegSetValueEx(hkey, 'TypesSupported', 0, win32con.REG_DWORD, eventLogFlags)
  21.     win32api.RegCloseKey(hkey)
  22.  
  23.  
  24. def RemoveSourceFromRegistry(appName, eventLogType = 'Application'):
  25.     
  26.     try:
  27.         win32api.RegDeleteKey(win32con.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (eventLogType, appName))
  28.     except win32api.error:
  29.         exc = None
  30.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  31.             raise 
  32.         exc.winerror != winerror.ERROR_FILE_NOT_FOUND
  33.  
  34.  
  35.  
  36. def ReportEvent(appName, eventID, eventCategory = 0, eventType = win32evtlog.EVENTLOG_ERROR_TYPE, strings = None, data = None, sid = None):
  37.     hAppLog = win32evtlog.RegisterEventSource(None, appName)
  38.     win32evtlog.ReportEvent(hAppLog, eventType, eventCategory, eventID, sid, strings, data)
  39.     win32evtlog.DeregisterEventSource(hAppLog)
  40.  
  41.  
  42. def FormatMessage(eventLogRecord, logType = 'Application'):
  43.     keyName = 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (logType, eventLogRecord.SourceName)
  44.     handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyName)
  45.     
  46.     try:
  47.         dllNames = win32api.RegQueryValueEx(handle, 'EventMessageFile')[0].split(';')
  48.         data = None
  49.         for dllName in dllNames:
  50.             
  51.             try:
  52.                 dllName = win32api.ExpandEnvironmentStrings(dllName)
  53.                 dllHandle = win32api.LoadLibraryEx(dllName, 0, win32con.LOAD_LIBRARY_AS_DATAFILE)
  54.                 
  55.                 try:
  56.                     data = win32api.FormatMessageW(win32con.FORMAT_MESSAGE_FROM_HMODULE, dllHandle, eventLogRecord.EventID, langid, eventLogRecord.StringInserts)
  57.                 finally:
  58.                     win32api.FreeLibrary(dllHandle)
  59.  
  60.             except win32api.error:
  61.                 pass
  62.  
  63.             if data is not None:
  64.                 break
  65.                 continue
  66.     finally:
  67.         win32api.RegCloseKey(handle)
  68.  
  69.     if not data:
  70.         pass
  71.     return u''
  72.  
  73.  
  74. def SafeFormatMessage(eventLogRecord, logType = None):
  75.     if logType is None:
  76.         logType = 'Application'
  77.     
  78.     
  79.     try:
  80.         return FormatMessage(eventLogRecord, logType)
  81.     except win32api.error:
  82.         if eventLogRecord.StringInserts is None:
  83.             desc = ''
  84.         else:
  85.             desc = u', '.join(eventLogRecord.StringInserts)
  86.         return u'<The description for Event ID ( %d ) in Source ( %r ) could not be found. It contains the following insertion string(s):%r.>' % (winerror.HRESULT_CODE(eventLogRecord.EventID), eventLogRecord.SourceName, desc)
  87.  
  88.  
  89.  
  90. def FeedEventLogRecords(feeder, machineName = None, logName = 'Application', readFlags = None):
  91.     if readFlags is None:
  92.         readFlags = win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ
  93.     
  94.     h = win32evtlog.OpenEventLog(machineName, logName)
  95.     
  96.     try:
  97.         while None:
  98.             objects = win32evtlog.ReadEventLog(h, readFlags, 0)
  99.             if not objects:
  100.                 break
  101.             
  102.         win32evtlog.CloseEventLog(h)
  103.         return None
  104.  
  105.  
  106.